<?php
require_once(dirname(__FILE__).'/../../WildPack/WildPack.php');
$wp = new WildPack();
$wp->using('util');
$wp->using('base');

class TestWpValidator extends WpTestSuite
{
  
  /**
   * Preparation
   */
  public function prepare(){ return true; }
  
  /**
   * Test
   */
  public function test()
  {
    //-- Not null --
    $this->addMessage('Test not_null');
    $this->addResult('Not null (string)', true, WpValidator::validate('not_null', 'aa'), '===');
    $this->addResult('Not null (null)', false, WpValidator::validate('not_null', null), '===');
    $this->addResult('Not null (int)', true, WpValidator::validate('not_null', 2), '===');
    $this->addResult('Not null (float)', true, WpValidator::validate('not_null', 2.2), '===');
    $this->addResult('Not null (true)', true, WpValidator::validate('not_null', true), '===');
    $this->addResult('Not null (false)', true, WpValidator::validate('not_null', false), '===');
    
    //-- String --
    $this->addMessage('Test string');
    $this->addResult('String (string)', true, WpValidator::validate('string', 'aa'), '===');
    $this->addResult('String (empty)', true, WpValidator::validate('string', ''), '===');
    $this->addResult('String (double quotes)', true, WpValidator::validate('string', ""), '===');
    $this->addResult('String (number string)', true, WpValidator::validate('string', "123"), '===');
    $this->addResult('String (int)', false, WpValidator::validate('string', 123), '===');
    $this->addResult('String (bool)', false, WpValidator::validate('string', false), '===');
    
    //-- string_not_empty --
    $this->addMessage('Test string_not_empty');
    $this->addResult('String not_empty (string)', true, WpValidator::validate('string_not_empty', 'aa'), '===');
    $this->addResult('String not_empty (empty)', false, WpValidator::validate('string_not_empty', ''), '===');
    $this->addResult('String not_empty (double quotes)', false, WpValidator::validate('string_not_empty', ""), '===');
    $this->addResult('String not_empty (number string)', true, WpValidator::validate('string_not_empty', "123"), '===');
    $this->addResult('String not_empty (int)', false, WpValidator::validate('string_not_empty', 123), '===');
    $this->addResult('String not_empty (bool)', false, WpValidator::validate('string_not_empty', false), '===');
    
    //-- string_alpha --
    $this->addMessage('Test string_alpha');
    $this->addResult('String alpha (string)', true, WpValidator::validate('string_alpha', 'aa'), '===');
    $this->addResult('String alpha (empty)', true, WpValidator::validate('string_alpha', ''), '===');
    $this->addResult('String alpha (double quotes)', true, WpValidator::validate('string_alpha', ""), '===');
    $this->addResult('String alpha (number string)', false, WpValidator::validate('string_alpha', "123"), '===');
    $this->addResult('String alpha (int)', false, WpValidator::validate('string_alpha', 123), '===');
    $this->addResult('String alpha (bool)', false, WpValidator::validate('string_alpha', false), '===');
    
    //-- string_alphanumeric --
    $this->addMessage('Test string_alphanumeric');
    $this->addResult('String alphanumeric (string)', true, WpValidator::validate('string_alphanumeric', 'aa'), '===');
    $this->addResult('String alphanumeric (empty)', true, WpValidator::validate('string_alphanumeric', ''), '===');
    $this->addResult('String alphanumeric (double quotes)', true, WpValidator::validate('string_alphanumeric', ""), '===');
    $this->addResult('String alphanumeric (number string)', true, WpValidator::validate('string_alphanumeric', "123"), '===');
    $this->addResult('String alphanumeric (int)', false, WpValidator::validate('string_alphanumeric', 123), '===');
    $this->addResult('String alphanumeric (bool)', false, WpValidator::validate('string_alphanumeric', false), '===');
    $this->addResult('String alphanumeric (numeric and alpha)', true, WpValidator::validate('string_alphanumeric', "aaa123"), '===');
    $this->addResult('String alphanumeric (special chars)', false, WpValidator::validate('string_alphanumeric', "<-?aa12"), '===');
   
    //-- number --
    $this->addMessage('Test number');
    $this->addResult('Number (string)', false, WpValidator::validate('number', 'aa'), '===');
    $this->addResult('Number (empty string)', false, WpValidator::validate('number', ''), '===');
    $this->addResult('Number (double quotes)', false, WpValidator::validate('number', ""), '===');
    $this->addResult('Number (number string)', false, WpValidator::validate('number', "123"), '===');
    $this->addResult('Number (int)', true, WpValidator::validate('number', 123), '===');
    $this->addResult('Number (float)', true, WpValidator::validate('number', 123.12), '===');
    $this->addResult('Number (bool)', false, WpValidator::validate('number', false), '===');
    $this->addResult('Number (null)', false, WpValidator::validate('number', null), '===');
    
    //-- integer --
    $this->addMessage('Test integer');
    $this->addResult('Integer (string)', false, WpValidator::validate('integer', 'aa'), '===');
    $this->addResult('Integer (empty string)', false, WpValidator::validate('integer', ''), '===');
    $this->addResult('Integer (double quotes)', false, WpValidator::validate('integer', ""), '===');
    $this->addResult('Integer (number string)', false, WpValidator::validate('integer', "123"), '===');
    $this->addResult('Integer (int)', true, WpValidator::validate('integer', 123), '===');
    $this->addResult('Integer (float)', false, WpValidator::validate('integer', 123.12), '===');
    $this->addResult('Integer (bool)', false, WpValidator::validate('integer', false), '===');
    $this->addResult('Integer (null)', false, WpValidator::validate('integer', null), '===');
    
    //-- uuid --
    $this->addMessage('Test uuid');
    $this->addResult('Uuid (string)', false, WpValidator::validate('uuid', 'aa'), '===');
    $this->addResult('Uuid (empty)', false, WpValidator::validate('uuid', ''), '===');
    $this->addResult('Uuid (double quotes)', false, WpValidator::validate('uuid', ""), '===');
    $this->addResult('Uuid (number string)', false, WpValidator::validate('uuid', "123"), '===');
    $this->addResult('Uuid (int)', false, WpValidator::validate('uuid', 123), '===');
    $this->addResult('Uuid (bool)', false, WpValidator::validate('uuid', false), '===');
    $this->addResult('Uuid (bool)', true, WpValidator::validate('uuid', '641abed0-ed82-11df-98cf-0800200c9a66'), '===');
    $this->addResult('Uuid (bool)', false, WpValidator::validate('uuid', '641abed0-ed82-11df-98cf-08002'), '===');
    $this->addResult('Uuid (bool)', false, WpValidator::validate('uuid', '641abed0-ed82-g1df-98cf-0800200c9a66'), '===');
    
    //-- email --
    $this->addMessage('Test email');
    $this->addResult('Email (string)', false, WpValidator::validate('email', 'aa'), '===');
    $this->addResult('Email (empty)', false, WpValidator::validate('email', ''), '===');
    $this->addResult('Email (double quotes)', false, WpValidator::validate('email', ""), '===');
    $this->addResult('Email (number string)', false, WpValidator::validate('email', "123"), '===');
    $this->addResult('Email (int)', false, WpValidator::validate('email', 123), '===');
    $this->addResult('Email (bool)', false, WpValidator::validate('email', false), '===');
    $this->addResult('Email (starts with with number)', true, WpValidator::validate('email', '123m@aa.de'), '===');
    $this->addResult('Email (starts with with number)', true, WpValidator::validate('email', '123@aa.de'), '===');
    $this->addResult('Email (domain only number)', true, WpValidator::validate('email', '123@123.de'), '===');
    $this->addResult('Email (domain ends only number)', false, WpValidator::validate('email', '123@123.123'), '===');
    $this->addResult('Email (special char)', false, WpValidator::validate('email', 'ß123@123.de'), '===');
    $this->addResult('Email (special char)', false, WpValidator::validate('email', '123@1ß23.de'), '===');
    $this->addResult('Email (special char)', false, WpValidator::validate('email', '123@123.deß'), '===');
    $this->addResult('Email (special char)', false, WpValidator::validate('email', '?123@123.de'), '===');
    $this->addResult('Email (special char)', false, WpValidator::validate('email', '123@1?23.de'), '===');
    $this->addResult('Email (special char)', false, WpValidator::validate('email', '123@123.de?'), '===');
    $this->addResult('Email (dot)', true, WpValidator::validate('email', 'aa.123@123.de'), '===');
    $this->addResult('Email (dot)', true, WpValidator::validate('email', '123@aa.123.de'), '===');
    
    //-- url --
    $this->addMessage('Test url');
    $this->addResult('Url (string)', false, WpValidator::validate('url', 'aa'), '===');
    $this->addResult('Url (empty)', false, WpValidator::validate('url', ''), '===');
    $this->addResult('Url (double quotes)', false, WpValidator::validate('url', ""), '===');
    $this->addResult('Url (number string)', false, WpValidator::validate('url', "123"), '===');
    $this->addResult('Url (int)', false, WpValidator::validate('url', 123), '===');
    $this->addResult('Url (bool)', false, WpValidator::validate('url', false), '===');
    $this->addResult('Url (no protocol)', false, WpValidator::validate('url', 'aa.de'), '===');
    $this->addResult('Url (http)', true, WpValidator::validate('url', 'http://aa.de'), '===');
    $this->addResult('Url (http www)', true, WpValidator::validate('url', 'http://www.aa.de'), '===');
    $this->addResult('Url (without end)', true, WpValidator::validate('url', 'http://www.aa'), '===');
    $this->addResult('Url (param)', true, WpValidator::validate('url', 'http://www.aa.de?aa=aa'), '===');
    $this->addResult('Url (params)', true, WpValidator::validate('url', 'http://www.aa.de?aa=aa&bb'), '===');
    $this->addResult('Url (only ?)', true, WpValidator::validate('url', 'http://www.aa.de?'), '===');
    $this->addResult('Url (only &)', false, WpValidator::validate('url', 'http://www.aa.de&'), '===');
    $this->addResult('Url (ftp)', true, WpValidator::validate('url', 'ftp://www.aa.de'), '===');
    $this->addResult('Url (https)', true, WpValidator::validate('url', 'https://www.aa.de'), '===');
    $this->addResult('Url (custom protocol)', true, WpValidator::validate('url', 'aa://www.aa.de'), '===');
    $this->addResult('Url (slash)', true, WpValidator::validate('url', 'aa://www.aa.de/abc'), '===');
    
  }
  
  /**
   * Cleanup
   */
  public function cleanup(){}
  
  
}

$t = new TestWpValidator();
$t->start('WpValidator');
